from django.db import models
from log_reg.models import *
from django.utils import timezone
from ckeditor_uploader.fields import RichTextUploadingField
from eat.models import *
# Create your models here.
# 临时订单表
class Order_lingshi(models.Model):
    # 食品图片,RichTextUploadingField上传类型
    img = RichTextUploadingField(config_name='my_config')
    # 食品名称,models.CharField字符串类型
    food_name = models.CharField(max_length=255)
    # 购买数量,models.IntegerField数字类型
    food_num = models.IntegerField(default=1)
    # 金额
    food_money = models.FloatField()
    # 一对多连接用户表
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    # 食品id
    eat_food = models.CharField(max_length=255)

# 订单表
class Order_1(models.Model):
    # 订单编号,models.CharField字符串类型
    order_id = models.CharField(max_length=255)
    # 订单日期,models.DateField日期类型
    order_data = models.DateTimeField(default=timezone.now)
    # 订单总金额
    order_money_all = models.FloatField()
    # 下单用户,models.CharField字符串类型
    order_user = models.CharField(max_length=255)
    # 支付方式
    payway = models.CharField(max_length=20, default='alipay')
    # 支付状态
    pay_case = models.CharField(max_length=255,default='未支付')
    # 商户和支付宝交易的一个凭证
    trade_no = models.CharField(max_length=120, default='')
    # 收货地址
    address = models.CharField(max_length=255)
    # 收货人电话
    tel = models.CharField(max_length=255)
    # 一对多连接用户表
    user = models.ForeignKey(User,on_delete=models.CASCADE)

    def __str__(self):
        return "%s" % self.order_id

# 订单明细表
class Order_2(models.Model):
    # 食品名称,models.CharField字符串类型
    Order_food = models.CharField(max_length=255)
    # 购买数量,models.IntegerField数字类型
    Order_num = models.IntegerField()
    # 金额
    food_money = models.FloatField()
    # 对应订单编号,models.CharField字符串类型
    Order_id = models.CharField(max_length=255)
    # 对应订单日期,models.CharField字符串类型
    Order_data = models.CharField(max_length=255)
    # 一对多连接订单表
    order_1 = models.ForeignKey(Order_1, on_delete=models.CASCADE)

# 评论表
class Comment(models.Model):
    # 内容
    comment = models.CharField(max_length=10000,default='')
    # 照片
    photo = models.ImageField(default='',upload_to='media')
    # 星级
    lv = models.IntegerField()
    # 一对多关联用户
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    # 一对多关联订单
    order_1 = models.ForeignKey(Order_1, on_delete=models.CASCADE)